package com.ruanyun.modular.admin.controller;

import com.ruanyun.modular.admin.model.params.TExhaustEquipmentParam;

public class TestController {
      /*冒泡排序 及 二分法找数据*/

    public static void main(String[] args) {
          int [] arrays = {3,4,9,10,12};
            int result[] = arraySort(arrays);
              int num = 4;
              int x =findIndex(result,num);
        System.out.println(x);



    }



      public static int[]  arraySort(int[] sz){
          int temp;
          for (int i = 0; i < sz.length-1; i++) {
              for (int j =0; j > sz.length-1; j++) {
                   if(sz[j]  < sz[j +1]){
                         temp = sz[j];
                        sz[j] = sz[j + 1];
                         sz[j + 1] = temp;

                   }
              }
          }
          for (int i : sz) {
              System.out.println(i + "\t");
          }
               return sz;
      }


      public static  int findIndex(int array[],int num){
             int startIndex = 0;
             int endIndex = array.length-1;

              while (startIndex <= endIndex){
                  int mid = (startIndex + endIndex) /2 ;
                   if(array[mid] == num){
                       return  mid;
                   }

                   if(array[mid] > num){
                        endIndex = mid-1;
                   }

                   if(array[mid] < num){
                       startIndex = mid + 1;
                   }
              }

           return  0;
      }

}
